package com.guigu.service.impl.manufacture;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.manufacture.MManufactureMapper;
import com.guigu.pojo.manufacture.MApply;
import com.guigu.pojo.manufacture.MManufacture;
import com.guigu.service.manufacture.MManufactureService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Service
public class MManufactureServiceImpl extends ServiceImpl<MManufactureMapper, MManufacture> implements MManufactureService {

    @Autowired
    private MManufactureMapper manufactureMapper;

    @Override
    public MManufacture getEndManufacture() {
        QueryWrapper<MManufacture> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("manufacture_id");
        queryWrapper.last("limit 1");
        MManufacture mManufacture = manufactureMapper.selectOne(queryWrapper);
        return mManufacture;
    }

    @Override
    public PageInfo<MManufacture> selectArrByPage(HashMap<String, Object> map) {
        Integer pageNum = 1;
        Integer pageSize = 5;

        Object pageNumObj = map.get("pageNum");
        if (pageNumObj != null && StringUtils.isNotBlank((String) pageNumObj)) {
            pageNum = Integer.parseInt((String) pageNumObj);
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null && StringUtils.isNotBlank((String) pageSizeObj)) {
            pageSize = Integer.parseInt((String) pageSizeObj);
        }
        QueryWrapper<MManufacture> queryWrapper = new QueryWrapper<>();
        if (map.containsKey("checkTag")){
            queryWrapper.eq("CHECK_TAG",map.get("checkTag"));
        }
        if (map.containsKey("manufactureProcedureTag")){
            queryWrapper.eq("MANUFACTURE_PROCEDURE_TAG",map.get("manufactureProcedureTag"));
        }
        PageHelper.startPage(pageNum,pageSize);
        List<MManufacture> mManufactures = manufactureMapper.selectList(queryWrapper);
        PageInfo<MManufacture> pageInfo = new PageInfo<>(mManufactures);
        return pageInfo;
    }

    @Override
    public MManufacture getManufactureByManufactureId(String manufactureId) {
        QueryWrapper<MManufacture> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("manufacture_id",manufactureId);
        MManufacture mManufacture = manufactureMapper.selectOne(queryWrapper);
        return mManufacture;
    }
}
